﻿using System;
using ACompany.OrderProcessing.Infrastructure;

namespace ACompany.OrderProcessing.Model
{
    public class Product : BusinessBase<Product>, IAggregateRoot
    {
        #region Fields

        public string Name { get; set; }
        public Decimal Price { get; set; }
        public int Stock { get; set; }

        #endregion


        protected override void Validate()
        {
            if (!(this.Stock >= 0))
                this.BrokenRules.Add(new BrokenRule("Stock", "Stock cannot be a negative number"));

            if (this.Price < 0)
                this.BrokenRules.Add(new BrokenRule("Price", "Price cannot be a negative number"));

            if (String.IsNullOrEmpty(this.Name))
                this.BrokenRules.Add(new BrokenRule("Name", "Name is a required value"));
            else if (this.Name.Length > 50)
                this.BrokenRules.Add(new BrokenRule("Name", "Name should be 50 chars or less"));

        }


    }
}
